import React, {Component} from 'react'
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'
import { Router, Route, Link, browserHistory, IndexRoute } from 'react-router'
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'

import configureStore from './store/configureStore'

//
// import App from './containers/App';
// import Dashboard from './components/dashboard';
// import House from './components/house'
// import Customer from './components/customer'
// import Counter from './components/counter'
// import dictionary from './components/calculator'


//import Routes from './routes'

const store = configureStore()

const history = syncHistoryWithStore(browserHistory, store)

// export class Routes extends Component {
//     render() {
//         return (
//             <Router history={history}>
//                 <Route path="/" component={App}>
//                     <IndexRoute component={Dashboard}/>
//                     <Route path="house" component={House}/>
//                     <Route path="customer" component={Customer}/>
//                     <Route path="counter" component={Counter}/>
//                     <Route path="calculator" component={dictionary}/>
//                 </Route>
//             </Router>
//         );
//     }
// }


const routes = require('./routes/index').default(store)

let render = () => {
    ReactDOM.render(
        <Provider store={store}>
            <Router
                history={history}
                routes={routes}
            />
        </Provider>
        ,document.getElementById('app'));
}

if (module.hot) {
    // Development render functions
    // const renderApp = render
    // const renderError = (error) => {
    //     const RedBox = require('redbox-react').default
    //
    //     ReactDOM.render(<RedBox error={error} />, MOUNT_NODE)
    // }
    //
    // // Wrap render in try/catch
    // render = () => {
    //     try {
    //         renderApp()
    //     } catch (error) {
    //         renderError(error)
    //     }
    // }

    // Setup hot module replacement
    // module.hot.accept('./routes/index', () => {
    //     setTimeout(() => {
    //         ReactDOM.unmountComponentAtNode(MOUNT_NODE)
    //         render()
    //     })
    // })
}


render()